<?php

namespace app\api\controller;

use app\admin\model\factor\Category as FactoryCategoryModel;
use app\admin\model\template\TemplateCategory;
use app\common\controller\Api;

/**
 * 碳排放因子库
 */
class Category extends Api
{
    // 验证失败是否抛出异常
    protected $failException = true;
    protected $noNeedLogin = [];
    protected $noNeedRight = ["*"];

    public function _initialize()
    {
        parent::_initialize();
    }

    /**
     * @title 碳因子分类列表
     * @author Trace
     * @method GET
     * @url http://xx.com/api/category/getFactorCategoryList
     * @param xx 必选 string 用户名
     * @return_param error_code int 返回码
     * @DATE: 2024/9/9
     * @TIME: 11:02
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function getFactorCategoryList()
    {
        $list = FactoryCategoryModel::field('id,name')->select();
        $this->success('获取成功',$list);
    }


    /**
     * @title 模板分类列表
     * @author Trace
     * @method GET
     * @url http://xx.com/api/category/getTemplateCategoryList
     * @param xx 必选 string 用户名
     * @return_param error_code int 返回码
     * @DATE: 2024/9/9
     * @TIME: 11:02
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function getTemplateCategoryList()
    {
        $list = TemplateCategory::field('id,pid,name')->select();
        $this->success('获取成功',list_to_tree($list->toArray()));

    }
}
